<!--
// +----------------------------------------------------------------------
// | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/3/24-14:54
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------
*-->

{extend name='public/base' /}

{block name="css"}

<link rel="stylesheet" href="__PLUGS__/editormd-master/css/editormd.css?v=1">


{/block}

{block name="content"}

<!--左侧开始-->
<div class="layui-col-md3 ">
    <div class="layui-card">
        <div class="layui-card-header">
            文件列表
        </div>
        <div class="layui-card-body layui-row ">
            <div class="demo-tree-more" style="width: 100%; height: 500px; overflow: scroll;" id="menuLfetTree">
            </div>
        </div>

    </div>

</div>
<!--左侧结束-->


<div class="layui-col-md9">

    <div class="layui-card">
        <div class="layui-card-header" id="title" style="line-height: 55px;text-align: center;font-weight: bold;">
        </div>
        <div class="layui-card-body">

            <div id="test-editormd">

            </div>

        </div>
    </div>
</div>


{/block}

{block name="js"} <!--js处理区-->

<script src="__PLUGS__/editormd-master/editormd.js"></script>

<script>
    layui.use(['element', 'laytpl', 'form', 'jquery', 'lucky','tree'], function () {
        var element = layui.element;
        var form = layui.form;
        var laytpl = layui.laytpl;
        var $ = layui.jquery;
        var lucky=layui.lucky;
        var tree=layui.tree;
        form.render();
        var datas={:json_encode($filelist)};
        //基本演示

        var testEditor = editormd("test-editormd", {
            width            : "90%",
            height           : 650,
            watch            : false,
            toolbar          : false,
            codeFold         : true,
            searchReplace    : true,
            placeholder      : "Enjoy coding!",
            value            : '',
            theme            : "dark",
            mode             : "text/html",
            path             : '__PLUGS__/editormd-master/lib/'
        });
        tree.render({
            elem: '#menuLfetTree'
            ,data: datas
            ,showCheckbox: false  //是否显示复选框
            ,id: 'demoId1'
            ,edit: ['del'] //操作节点的图标
            ,isJump: false //是否允许点击节点时弹出新窗口跳转
            ,click: function(obj){
                var data = obj.data;  //获取当前点击的节点数据
                if (data.type=="file"){
                    $.ajax({
                        beforeSend:function(){
                            layer.load(2);
                        },
                        url: "{:url('getContent')}",
                        type: "POST",
                        async: true,
                        dataType: "json",
                        data:{
                            path:data.path
                        },
                        error: function(error) {
                            layer.msg("服务器错误或超时");
                            return false;
                        },
                        success: function(da) {
                            if (da.code==1) {
                                $("#title").html(data.title);
                                testEditor.setValue(da.data);
                            }else{
                                layer.msg(da.msg,{icon:15,time:1500,shade:0.3},function () {
                                });
                            }
                        },
                        complete:function(){
                            layer.closeAll('loading');
                        }
                    });
                }
            },operate:function (obj) {
                var data = obj.data;  //获取当前点击的节点数据
                $.ajax({
                    beforeSend:function(){
                        layer.load(2);
                    },
                    url: "{:url('del_file')}",
                    type: "POST",
                    async: true,
                    dataType: "json",
                    data:{
                        path:data.path,
                        type:data.type
                    },
                    error: function(error) {
                        layer.msg("服务器错误或超时");
                        return false;
                    },
                    success: function(da) {
                        layer.msg(da.msg,{icon:15,time:1500,shade:0.3});
                    },
                    complete:function(){
                        layer.closeAll('loading');
                    }
                });
            }
        });
    });

</script >


{/block}
